home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
7_10.lha
/
7_10
/
p_save.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
35 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <process.h>
include <debug.h> /* DELETE */
include <stackdir.h>
/ Save the current state of this process.
/ Returns true when coming back from another process.
nt process::contextswitch()
// Copy the stack out, but first make
// certain we're above t_stackbase
if (debug) /*DELETE*/ cerr << "process" << this << "::contextswitch()\n";
if (mustrecurse())
return contextswitch();
char *px = Stackdir.plusone();
t_stacksize = Stackdir.diff(px, t_stackbase);
if (debug) /*DELETE*/ cerr << "\tt_stacksize <- " << t_stacksize << "\n";
if (t_stack)
delete t_stack;
t_stack = new char[t_stacksize];
if (Stackdir.grows_up())
memcpy(t_stack, t_stackbase, t_stacksize);
else
memcpy(t_stack, px, t_stacksize);
int ret = setjmp(t_jb);
if (debug) /*DELETE*/ cerr << "<<<< process" << this << "::contextswitch() <- " << (ret ? "from longjmp" : "from setjmp") << "\n";
return ret;